﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp
{
    public class DebugAndRelease
    {
        /// <summary>
        /// 以下代码，debug和release不一样
        /// c#中写是易失性写，读是非易失性读，在本文中可以理解为，c#会对对象读取做一定的优化。
        /// </summary>
        public void Show()
        {
            int i = 1;

            Task.Run(() => { i = int.MinValue; });

            do { }
            while (i > 0);
        }

        public void Show2()
        {
            for (int i = 0; i < 1000; i++)
            {
                Thread.Sleep(1000);
                DebugWrite("这是调试信息");
            }
        }

        //[ConditionalAttribute("DEBUG")]
        public static void DebugWrite(string str)
        {
#if DEBUG
            Debug.WriteLine($"[Bruke-debug]:{str}");
#else
            Debugger.Log(0, null, $"[Bruke-release]:{str}");
#endif

            //配合项目属性，定义的【条件编译符合】进行命中编译
#if Bruke
            //Debug.WriteLine($"[Bruke-Bruke]:{str}");
#endif
#if Macy
            //Debug.WriteLine($"[Bruke-Macy]:{str}");
#endif

#if Release
            //Debug.WriteLine($"[Bruke-Release]:{str}");
#endif

        }
    }
}
